﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using nRoute.Components;
using nRoute.Mapping;
using nRoute.SiteMaps;
using nRoute.ViewModels;

namespace SimpleShell.ViewModels
{
    [MapViewModel(typeof(Shell))]
    public class ShellViewModel : ViewModelBase
    {
        public ShellViewModel()
        {
            LoadSiteMap();
        }

        public IEnumerable<SiteMapNode> SiteMapNodes { get; private set; }

#region Helpers

        private void LoadSiteMap()
        {
            // SiteMaps are loaded asynchronously 
            SiteMapService.LoadSiteMap((s) =>
            {
                if (s != null && s.RootNode != null)
                {
                    this.SiteMapNodes = s.RootNode.ChildNodes;
                    NotifyPropertyChanged(() => SiteMapNodes);
                }
            });
        }

#endregion

    }
}